package org.finesys.system.api.feignFactory;

import org.finesys.common.core.module.R;
import org.finesys.system.api.dto.ClientDetailsDto;
import org.finesys.system.api.feign.ClientServiceApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;


@Component
@ConditionalOnProperty(name = "feign.enabled", havingValue = "true")
public class ClientServiceApiFallbackFactory implements FallbackFactory<ClientServiceApi> {

    @Override
    public ClientServiceApi create(Throwable cause) {
        return new ClientServiceApi() {
            @Override
            public R<ClientDetailsDto> getByClientId(String clientId) {
                return R.failed(String.format("获取客户端[%s]信息失败:%s", clientId, cause.getLocalizedMessage()));
            }
        };
    }
}
